home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1993…ch: Other People's Memory / ADC Developer CD (1993-03) (''Other People's Memory'')_iso / Dev.CD Mar 93.iso / Technical Documentation / Sample Code / DTS.Lib & Samples / DTS.Chat / File2.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-10-22  |  4.9 KB  |  176 lines  |  [TEXT/MPS ]

  1. /*
  2. ** Apple Macintosh Developer Technical Support
  3. **
  4. ** File:        File2.c
  5. ** Written by:    Eric Soldan
  6. **
  7. ** Copyright © 1990-1992 Apple Computer, Inc.
  8. ** All rights reserved.
  9. */
  10.  
  11. /* This file is where you place various definitions and constant values for
  12. ** DTS.Lib..framework's use.  You will also add some code within the two
  13. ** functions to handle the various document types. */
  14.  
  15.  
  16.  
  17. /*****************************************************************************/
  18.  
  19.  
  20.  
  21. #include "App.h"            /* Get the application includes/typedefs, etc.    */
  22. #include "App.Common.h"        /* Get the stuff in common with rez.            */
  23. #include "App.protos.h"        /* Get the prototypes for application.            */
  24.  
  25. #ifndef __ERRORS__
  26. #include <Errors.h>
  27. #endif
  28.  
  29. #ifndef __UTILITIES__
  30. #include "Utilities.h"
  31. #endif
  32.  
  33.  
  34.  
  35. /* In this file, we first set some global values.  This allows the application and
  36. ** DTS.Lib..framework to "know" what is expected for certain default actions. */
  37.  
  38.  
  39. OSType        gDocCreator = kDocCreator;    /* So DTS.Lib..framework knows who's boss. */
  40.  
  41. short        gTypeListLen = 2;
  42. SFTypeList    gTypeList = {kDocFileType, kTextFileType};
  43.     /* Here we declare the various document types that DTS.Chat can support.
  44.     ** These definitions are to inform DTS.Lib..framework what documents can be opened. */
  45.  
  46.  
  47.  
  48. /* Some DTS.Lib..framework gTypeList usage notes:
  49. **
  50. ** 1)  Framework uses gTypeList[0] for the default document, if there is one.
  51. ** 2)  NewDocument() is passed a document type.  It searches gTypeList for a match.
  52. **     The index at which the match is found (+1) is used as the string number in the
  53. **     STR# resource rDefaultTitles.  If there aren't enough strings in the STR#
  54. **     resource, then the last string is used.
  55. ** 3)  The gTypeList is used for the StandardFile calls to determine which files
  56. **     can be selected. */
  57.  
  58.  
  59.  
  60. typedef struct DocFileTypeRec {        /* This is used only to determine the size of the document  */
  61.     FileStateRec    fileState;        /* structure.  We can't just add the three components, as   */
  62.     ConnectRec        connect;        /* it is unclear how much padding any particular compiler   */
  63.     TheDoc            doc;            /* will place on the end of each.                            */
  64. } DocFileTypeRec;                    /* The only place that this should be used is in this file. */
  65.  
  66.  
  67.  
  68. /* Below are the TreeObj procedure pointers for the various kinds of objects we use in this
  69. ** application.  The first 16 are reserved for the framework.  Our application-specific
  70. ** objects start at 16. */
  71.  
  72. TreeObjProcPtr    gTreeObjMethods[kNumTreeObjs] = {nil,
  73. /* 1  */                                         TRootObj,
  74. /* 2  */                                         TUndoObj,
  75. /* 3  */                                         TUndoTaskObj,
  76. /* 4  */                                         TUndoPartObj,
  77. /* 5  */                                         nil,
  78. /* 6  */                                         nil,
  79. /* 7  */                                         nil,
  80. /* 8  */                                         nil,
  81. /* 9  */                                         nil,
  82. /* 10 */                                         nil,
  83. /* 11 */                                         nil,
  84. /* 12 */                                         nil,
  85. /* 13 */                                         nil,
  86. /* 14 */                                         nil,
  87. /* 15 */                                         nil};
  88. /* 16 Start of app-specific procs. */
  89.  
  90.  
  91.  
  92. /* The framework needs to know the minimum object sizes.  This table is used by the
  93. ** framework to make sure that the object is created at least minimally. */
  94.  
  95. long            gMinTreeObjSize[kNumTreeObjs] = {0,
  96. /* 1  */                                         sizeof(RootObj),
  97. /* 2  */                                         sizeof(UndoObj),
  98. /* 3  */                                         sizeof(UndoTaskObj),
  99. /* 4  */                                         sizeof(UndoPartObj),
  100. /* 5  */                                         0,
  101. /* 6  */                                         0,
  102. /* 7  */                                         0,
  103. /* 8  */                                         0,
  104. /* 9  */                                         0,
  105. /* 10 */                                         0,
  106. /* 11 */                                         0,
  107. /* 12 */                                         0,
  108. /* 13 */                                         0,
  109. /* 14 */                                         0,
  110. /* 15 */                                         0};
  111. /* 16 Start of app-specific sizes. */
  112.  
  113.  
  114.  
  115. /*****************************************************************************/
  116. /*****************************************************************************/
  117.  
  118.  
  119.  
  120. /* •• Called by DTS.Lib..framework. •• */
  121.  
  122. /* Do any additional document initialization here.  All fields not specifically set
  123. ** are already initialized to 0. */
  124.  
  125. #pragma segment File
  126. OSErr    InitDocument(FileRecHndl frHndl)
  127. {
  128.     OSType    sftype;
  129.  
  130.     switch (sftype = (*frHndl)->fileState.sfType) {
  131.         case kDocFileType:
  132.         case kTextFileType:
  133.             if (sftype == kTextFileType) {
  134.                 (*frHndl)->fileState.readDocumentHeaderProc  = nil;
  135.                 (*frHndl)->fileState.writeDocumentHeaderProc = nil;
  136.             }        /* Text files don't have a header, so prohibit header handling by
  137.                     ** setting the read and write header procs to nil. */
  138.             return(DefaultInitDocument(frHndl, kVersion, kMaxNumUndos, kNumSaveUndos));
  139.             break;
  140. #if VH_VERSION
  141.         case kViewHierFileType:
  142.             return(VHInitDocument(frHndl));
  143.             break;
  144. #endif
  145.     }
  146. }
  147.  
  148.  
  149.  
  150. /*****************************************************************************/
  151.  
  152.  
  153.  
  154. /* •• Called by DTS.Lib..framework. •• */
  155.  
  156. /* Return the initial size of the primary document handle, based on the OSType. */
  157.  
  158. #pragma segment File
  159. long    InitDocumentSize(OSType sftype)
  160. {
  161.     switch (sftype) {
  162.         case kDocFileType:
  163.         case kTextFileType:
  164.             return(sizeof(DocFileTypeRec));
  165.             break;
  166. #if VH_VERSION
  167.         case kViewHierFileType:
  168.             return(VHFileTypeSize());
  169.             break;
  170. #endif
  171.     }
  172. }
  173.  
  174.  
  175.  
  176.